package edu.cuit.codelibary.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.text.Html;

import edu.codelibary.common.util.HtmlService;
import edu.codelibary.common.util.JsonUtil;

public class ArticleDao {
	private static final String TAG = "ArticleTypeDao";

	public List<Map<String, Object>> findByAtID(int id) {
		String url =Host.URL+ "article/view.action?atId="+id;
		JSONArray array = null;
		try {
			JSONObject data = new JSONObject(HtmlService.getJson(url));
			array = data.getJSONArray("result");
			return JsonUtil.string2Map(array);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public Map<String, Object> findByID(int id) {
		String url =Host.URL+ "article/viewOne.action?atId="+id;
		JSONObject json = null;
		Map<String, Object> result=new HashMap<String, Object>();
		try {
			JSONObject data = new JSONObject(HtmlService.getJson(url));
			json = data.getJSONObject("result");
			result.put("title", json.get("title"));
			result.put("content", json.get("content"));
			result.put("createTime", json.get("createTime"));
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
